package com.itheima.test;

import com.itheima.domain.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;

import java.util.*;

@Controller
@RequestMapping("/freemarker")
public class Freemark_test01 {
    @Autowired
    RestTemplate restTemplate;
    @RequestMapping("/test03")
    public String test03(Map map){
        ResponseEntity<Map> entity = restTemplate.getForEntity("http://localhost:31200/course/courseView/find/297e7c7c62b888f00162b8a965510001", Map.class);
        Map body = entity.getBody();
        map.putAll(body);
        return "course";
    }
    @RequestMapping("/test02")
    public String test02(Map map){
        ResponseEntity<Map> entity = restTemplate.getForEntity("http://localhost:31001/cmsConfig/find/5a791725dd573c3574ee333f", Map.class);
        Map body = entity.getBody();
        map.putAll(body);
        return "index_banner";
    }
    @RequestMapping("/test01")
    public String test01(Map<String,Object> map){
        Student s1=new Student("和hah","北京",22);
        Student s2=new Student("kkak","杭州",32);
        Student s3=new Student("哈哈哈","上海",24);
        Student s4=new Student();
        List<Student> list =new ArrayList<>();
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        map.put("name","张三");
        map.put("aaa",list);
        Map<String,Student> hashMap=new HashMap<>();
        hashMap.put("st1",s1);
        hashMap.put("st2",s2);
        hashMap.put("st3",s3);
        map.put("map",hashMap);
        map.put("time",new Date());
        map.put("num",1213242343);

        return "test01";
    }
    public static Map getMap(){
        Map map=new HashMap();
        Student s1=new Student("和hah","北京",22);
        Student s2=new Student("kkak","杭州",32);
        Student s3=new Student("哈哈哈","上海",24);
        Student s4=new Student();
        List<Student> list =new ArrayList<>();
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        map.put("name","张三");
        map.put("aaa",list);
        Map<String,Student> hashMap=new HashMap<>();
        hashMap.put("st1",s1);
        hashMap.put("st2",s2);
        hashMap.put("st3",s3);
        map.put("map",hashMap);
        map.put("time",new Date());
        map.put("num",1213242343);
        return  map;
    }
}